import {computed, createApp} from 'vue'
import ElementPlus from 'element-plus'
import App from './App.vue'
import router from './router'
import * as ElementPlusIconsVue from 'element-plus'

import store from './store'

import 'element-plus/dist/index.css'
import '@/assets/styles/normalize/reset.less'
import '@/assets/styles/homePage.less'

import zhCn from 'element-plus/es/locale/lang/zh-cn'

const app = createApp(App)

const dict = computed(
    () =>
        store.getters['dict']
)

const dictToValue = (dictKey,dictValue) => {
    let text = '';
    if(!dictValue && dictValue!==0){
        return;
    }
    if(typeof dictValue === 'string'){
        const toValue = dictValue?.split(',').map(item => isNaN(Number(item))?item:Number(item));
        toValue?.forEach(vItem =>{
            text = text +( ( dict.value[dictKey]?.find(dictItem => dictItem.dictValue === vItem)?.dictLabel) || vItem) + ',';
        })
        text = text.substring(0, text.length - 1);
    }else{
        dict.value[dictKey]?.forEach(item =>{
            if(item.dictValue === Number(dictValue)){
                text = item.dictLabel
            }
        })
    }

    return text
}

app.provide('dictToValue',dictToValue)


app.use(router).use(ElementPlus, {
    locale: zhCn,
}).use(ElementPlusIconsVue).use(store).mount('#app')
